<?php 
class LoginController extends Controller
{
	public function ActionLogin($request)
	{
		SubscriptionModel::DeleteObsolete();
		if (isset($request['login']) && isset($request['pass']))
		{
			if (LoginModel::Check($request['login'], $request['pass']))
			{
				$_SESSION['admin'] = true;
				$_SESSION['login'] = $request['login'];
				$db = new DbContext();
				$connec = $db->getConnection();

				$query = "INSERT INTO connection (login, date) VALUES (?, NOW())";

				$q=$connec->prepare($query); 
				$q->execute(array($request['login'])) or die(print_r($q->errorInfo(), true));
			}
		}

		return isset($_SESSION['admin']);
	}
	
	public function ActionLogout()
	{
		$_SESSION['admin'] = null;
		$_SESSION['login'] = null;
	}
}
?>
